package com.wngbms.shard.config;

import com.alibaba.druid.pool.DruidDataSource;
import com.wngbms.shard.init.Ib;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

import javax.sql.DataSource;

@Slf4j
//@Configuration
@EnableConfigurationProperties({TConfig.class})
//@Import({ABean.class})
public class Config {

//    @Bean
//    public ABean aBean() {
//        return new ABean();
//    }

    @Primary
    @ConfigurationProperties(prefix = "spring.datasource")
    @Bean
    public DataSource dataSource() {
        log.info("init druid");
        return new DruidDataSource();
    }

    @ConfigurationProperties(prefix = "spring.datasource.secondary")
    @Bean
    public DataSource dataSource2() {
        log.info("init druid2");
        return new DruidDataSource();
    }

    @Bean(initMethod = "init")
    public Ib ib() {
        return new Ib();
    }

    public Config() {
        log.info("init");
    }
}
